import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

/**
* @description: 950. 按递增顺序显示卡牌
* @author hewei
* @date 2022/9/17 16:03
* @version 1.0
*/

public class DeckRevealedIncreasing {

    public int[] deckRevealedIncreasing(int[] deck) {
        Arrays.sort(deck);
        int n = deck.length;
        int[] ans = new int[n];
        Deque<Integer> queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            queue.add(i);
        }
        for (int i : deck) {
            ans[queue.poll()] = i;
            if (!queue.isEmpty()) queue.add(queue.poll());
        }
        return ans;
    }
}
